import {
	getExpressageList
} from '@/api/index.js'

export const uploadFie = (file) => {
	return new Promise((resolve, reject) => {
		let token = uni.getStorageSync('token');
		console.log(uni.getStorageSync("token"))
		uni.uploadFile({
			url: 'https://paole.hebeixiaoyu.cn/run/api/common/upload',
			// url: 'http://localhost:1949/run/common/upload',
			filePath: file?.tempFilePath || file?.path,
			name: 'file',
			formData: {
				file: file
			},
			header: {
				"Token": uni.getStorageSync("token"),
				"Content-Type": "application/json;charset=utf-8",
				"Authorization": `Bearer ${uni.getStorageSync("token")}`,
				"Authori-zation": uni.getStorageSync("token")
			},
			async success(res) {
				let result = JSON.parse(res.data).data;
				let fileObj = {
					url: result.fullurl,
					urlKey: result.url
				}
				resolve(fileObj)
			},
			fail(err) {
				reject(err)
			}
		})
	})
}

export const getList = async () => {
	try {
		let res = await getExpressageList();
		return res
	} catch (e) {
		//TODO handle the exception
	}
}

export const payFlag = (errors) => {
	let flag = Object.values(errors).every(item => {
		return item == ""
	})
	return flag
}